package ysq.xyg.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.github.pagehelper.StringUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import tk.mybatis.mapper.entity.Example;
import ysq.xyg.dao.StoreDao;
import ysq.xyg.model.Store;
import ysq.xyg.service.StoreService;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author yu sheng qiang
 * @create 2017-03-22 15:37
 **/
@Service("storeService")
public class StoreServiceImpl extends BaseServiceImpl<Store> implements StoreService {
    @Resource
    private StoreDao storeDao;

    @Autowired
    public void setBaseDao(StoreDao storeDao) {
        this.baseDao = storeDao;
    }

    @Override
    public PageInfo<Store> pageInfo(Store store, int pageSize, int pageNum) {
        PageHelper.startPage(pageNum,pageSize);
        PageHelper.orderBy(" sort desc");
        //通用Example查询
        Example example = new Example(Store.class);
        Example.Criteria criteria = example.createCriteria();
        if (StringUtil.isNotEmpty(store.getName())) {
            criteria.andLike("name","%"+store.getName()+"%");
        }
        List<Store> list=storeDao.selectByExample(example);
        return new PageInfo<Store>(list);
    }
    public List<Store> list(Store store) {
        //通用Example查询
        Example example = new Example(Store.class);
        example.setOrderByClause(" sort desc");
        Example.Criteria criteria = example.createCriteria();
        if (StringUtil.isNotEmpty(store.getName())) {
            criteria.andLike("name","%"+store.getName()+"%");
        }
        List<Store> list=storeDao.selectByExample(example);
        return list;
    }
}
